<?php

namespace App\Logics;

use App\Models\Admin;
use App\Service\Base\Logic;

class AdminLogic extends Logic
{

    // 获取所有的
    public function getAll()
    {
        $where = [];
        $model = new Admin();
        $args  = compact('where');

        // 获取缓存
        $cFile = $model->cacheKey('lists', $args);
        $lists = $model->getCache($cFile);
        if(empty($lists)){
            $lists = $model->getAll($where);
            // 保存为缓存
            $model->addCacheList($lists, $cFile, $lists, 'list');
        }



        $sql    = $model->getSql();
        $result = ['sql' => $sql, 'data' => $lists,];

        return $result;
    }

    // 修改用户名的密码
    public function password()
    {
        $option   = $this->option();
        $username = $option->getData('username');
        $model    = new Admin();

        $where = ['username' => $username];
        $data  = ['password' => 123456,];
        $data  = $model->checkData($data, $where);
        $this->throwIf($data === false, $model->getError());

        $result = $model->oneEdit($where, $data);

        return $result;
    }

}


